package com.common.manager.net.asynchttp;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.common.R;
import com.common.utility.CommonUtility;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.RequestParams;


public class ProjectAsyncHttpClient extends AsyncHttpClient{
	
	private static final String TAG = "ProjectAsyncHttpClient";
	private static final int TIME_OUT = 10000;
	
	public ProjectAsyncHttpClient(){
		super();
		setTimeout(TIME_OUT);
	}
	
	public void get(Context context, String url, RequestParams params, ProjectAsyncHttpResponseHandler responseHandler) {
		if(!CommonUtility.DeviceInfoUtility.isConnect(context)){
			Log.d(TAG, "网络连接失败");
			this.showDialog(context.getResources().getString(R.string.can_not_read_network_data),context);
            return;
		}
        printUrl(url,params);
		super.get(context, url, params, responseHandler);
	}
	
	private void showDialog(String msg,Context context){
        CommonUtility.DialogUtility.confirm(context,"温馨提示",msg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
	}

    public void post(Context context,String url,RequestParams params,ProjectAsyncHttpResponseHandler responseHandler){

        if(!CommonUtility.DeviceInfoUtility.isConnect(context)){
            Log.d(TAG, "网络连接失败");
            this.showDialog(context.getResources().getString(R.string.can_not_read_network_data),context);
            return;
        }
        printUrl(url,params);
        super.post(context, url, params, responseHandler);
    }


    private void printUrl(String url,RequestParams params){
        Log.e("url",url + "?"+params.toString());
        System.out.println(url + "?"+params.toString());

    }
}
